CONTENTS | INDEX | PREV | NEXT
 fflush

 NAME
  fflush - flush buffers to file

 SYNOPSIS
  #include <stdio.h>

  int error = fflush(fp);
  FILE *fp;

 FUNCTION
  fflush writes out any buffered data out to the file descriptor
  associated with the file pointer.

  Normally a file is either unbuffered, line buffered, or fully
  buffered.  fflush is useful in the later two cases as is shown
  by the example.

  fflush will return -1 if a write error occured, 0 if no error
  occured.

 NOTE
  refer to the file_pointer manual page for general information

 EXAMPLE
  /*
   *  Since text to stdout is normally line buffered, if we do not
   *  write out a newline 'n' then the line is still buffered in
   *  memory and we have to fflush() to write it out.
   */

  #include <stdio.h>

  main()
  {
      char buf[256];

      printf("Enter a number -");
      fflush(stdout);
      gets(buf);
      printf("Munch Munch...");
      fflush(stdout);
      sleep(1);
      puts("Thanks!");
  }

 INPUTS
  FILE *fp;   file pointer

 RESULTS
  int error;  0 if no error, -1 on error.

 SEE ALSO
  fopen, fclose, fread, fwrite, fgets, fputs